﻿using Microsoft.Practices.Composite.Modularity;
using Microsoft.Practices.Composite.Regions;
using Microsoft.Practices.Unity;
using Shatkotha.WPF.Global;
using Shatkotha.WPF.Global.Modules;
using Shatkotha.WPF.Global.Modules.Home;
using Shatkotha.WPF.Home.Presenters;
using Shatkotha.WPF.Home.Views;

namespace Shatkotha.WPF.Home
{
    public class HomeModule : IHomeModule
    {
        private readonly IRegionManager _regionManager;
        private IUnityContainer _container;

        public HomeModule(IRegionManager regionManager,IUnityContainer container)
        {
            _container = container;
            _regionManager = regionManager;

            container.RegisterType(typeof(IHomeView), typeof(HomeView), new ContainerControlledLifetimeManager());
            container.RegisterType(typeof(IHomePresenter), typeof(HomePresenter), new ContainerControlledLifetimeManager());

            container.RegisterType(typeof(IHeaderView), typeof(HeaderView), new ContainerControlledLifetimeManager());
            container.RegisterType(typeof(IHeaderPresenter), typeof(HeaderPresenter), new ContainerControlledLifetimeManager());

            container.RegisterType(typeof(IFooterView), typeof(FooterView), new ContainerControlledLifetimeManager());
            container.RegisterType(typeof(IFooterPresenter), typeof(FooterPresenter), new ContainerControlledLifetimeManager());

            container.RegisterType(typeof(IMenuBarView), typeof(MenuBarView), new ContainerControlledLifetimeManager());
            container.RegisterType(typeof(IMenuBarPresenter), typeof(MenubarPresenter), new ContainerControlledLifetimeManager());
        }


        public void Initialize()
        {
            _regionManager.Regions[RegionNames.RegionHeader].Add(_container.Resolve<IHeaderPresenter>().View);
            _regionManager.Regions[RegionNames.RegionMenuBar].Add(_container.Resolve<IMenuBarPresenter>().View);
            _regionManager.Regions[RegionNames.RegionFooter].Add(_container.Resolve<IFooterPresenter>().View);
            _regionManager.Regions[RegionNames.RegionMain].Add(_container.Resolve<IHomePresenter>().View);
        }
    }
}
